package jesstest;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import jesstest.model.EquipmentConfig;
import jesstest.model.OS;
import jesstest.model.Problem;
import jesstest.model.Profile;

import jess.JessException;


public class JessDemo 
{

	public static void main(String[] args) 
	{
		try 
		{
			ArrayList<Profile> profiles = new ArrayList<Profile>();
			
			Profile pr1 = new Profile("Ann", new EquipmentConfig(OS.ANDROID, 1), 5); //GPRS
			profiles.add(pr1);
			Profile pr2 = new Profile("John", new EquipmentConfig(OS.WINDOWS, 3), 2); //WIFI
			profiles.add(pr2);
			Profile pr3 = new Profile("Nick", new EquipmentConfig(OS.ANDROID, 2), 3); //NG
			profiles.add(pr3);
			Profile pr4 = new Profile("Bob", new EquipmentConfig(OS.ANDROID, 1), 4); //GPRS
			profiles.add(pr4);
			Profile pr5 = new Profile("Dick", new EquipmentConfig(OS.WINDOWS, 3), 4); //WIFI
			profiles.add(pr5);
			
			//Problem p1 = new Problem("Simple problem", "2 + 2 = ?");
			Problem p1 = new Problem("Video problem", "2 + 2 = ?", "http://youtube.com", 12000);
			
			RecipientsSelectionEngine engine = new RecipientsSelectionEngine(p1);
				
			generateSendList(engine, profiles);

		} 
		catch (JessException e) 
		{
			e.printStackTrace();
		}

	}

	private static void generateSendList(RecipientsSelectionEngine engine, List<Profile> profiles ) throws JessException 
	{
	
		Iterator selected;
		
		long b = System.currentTimeMillis();
		for (Profile  p : profiles)
		{
			selected = engine.run(p);
			if (selected.hasNext()) 
				System.out.println(p.getNickName() + " was chosen!" );
		}
		 long e = System.currentTimeMillis();
	     System.out.println("It took "+(e-b)+ " milliseconds to form the list using JESS.");	
		 //Average execution time 30 milliseconds
	}

}
